Ext.define('AM.view.MyJobView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.myJobView',
		store : 'MyJobStore',
		columnLines:true,
		plugins: [{
            ptype: 'rowexpander',
            rowBodyTpl : new Ext.XTemplate(
                '<p><b>要求:</b> {jobRequirement}</p>'
//                '<p><b>备注:</b> {remark}</p><br>'  
            )
        }],
          viewConfig: {  
            forceFit:true,//当行大小变化时始终填充满  
            enableRowBody:true,//可以用两行tr来表示一行数据  
            showPreview:true,//初始显示预览效果,这个是自定义的属性  
            getRowClass : function(record,rowIndex,rowParams,store){  
        	var ni=record.get('planCompleteDate');
        	var hao=new Date();
        	if((ni-hao)/1000/60/60<24){
        		  cls = 'red_row';
        	}
        	if((ni-hao)/1000/60/60>24){
        		  cls = 'red_row';
        	}
        	return cls;
        	}
        },
		columns: [
			        { text: '序号', width:50,align:'center', xtype: 'rownumberer'},
			        { text: '任务性质',  dataIndex: 'tastproperty',  width:80,align:'center',renderer: function(value){
								 if (value === 0) {
										 return '创新性工作';
								 }	
								 if (value === 1) {
									 return '<font color=blue></font><span style="color:red;">一级</span>'; 
								 }
								 if (value ===2) {
								 	return '<font color=blue></font><span style="color:red;">二级</span>'
								 }
								 if (value ===3) {
								 	return '<font color=blue></font><span style="color:yellow;">三级</span>'	
								 }	
								 if (value ===4) {
								 	return '<font color=blue></font><span style="color:green;">四级</span>'	
								 }					 
						 }
			        },
			        { text: '名称', dataIndex: 'name', width:90,align:'center'},
			        { text: '步骤', dataIndex: 'step', width:50,align:'center'},
			        { text: '所属项目', dataIndex:'job.name', width:90,align:'center'},
			        { text: '开始时间', dataIndex: 'startdate', width:100,align:'center',xtype: 'datecolumn',   format:'Y-m-d'},
			        { text: '计划完成时间',  dataIndex: 'planCompleteDate',  width:100,align:'center',xtype: 'datecolumn',   format:'Y-m-d' },
//			        { text: '得分',dataIndex: 'core', width:50,align:'center' },
			        { text: '状态', dataIndex: 'state',  width:80,align:'center',renderer: function(value){
								 if (value === 2) {
										 return '<span style="color:green;">办理中</span>';
								 }if (value ===1) {
										  return '<span style="color:purple;">未办理</span>'; 
								 }if (value === 3) {
										 return '<span style="color:red;">结束</span>';
								 }	
						}					 
			        },
			        { text: '要求', dataIndex: 'jobRequirement', width:150,align:'center'},
//			        { text: '备注',dataIndex: 'remark', width:80,align:'center' },
			        { text: '操作', dataIndex: 'id',width:220,align:'center',renderer : function(data, cell, record, rowIndex,columnIndex){			        	
			        	    var resultStr = "<div class='controlBtn'>" +     
                            "<a href='javascript:void("+record.get('id')+");'class='alarm_detail'onclick='banLiJob("+record.get('id')+")'>办理任务</a>&nbsp;&nbsp;&nbsp;&nbsp;" +     
                            "<a href='javascript:void("+record.get('id')+");' class='alarm_detail'onclick='wanchengJob("+record.get('id')+")'>完成任务</a>&nbsp;&nbsp;&nbsp;&nbsp;"+ 
                          //   "<a href='javascript:void("+record.get('id')+");'class='alarm_detail'onclick='addRemark("+record.get('id')+")'>添加备注</a>&nbsp;&nbsp;&nbsp;&nbsp;"  
                             "<a href='javascript:void("+record.get('id')+");'class='alarm_detail'onclick='addRemar("+record.get('id')+")'>下载附件</a>&nbsp;&nbsp;&nbsp;&nbsp;"   
//                            "<a href='javascript:void("+record.get('id')+");' class='alarm_detail'onclick='addAdvice("+record.get('id')+")'>建议</a>"  
                            "</div>";     
         					return resultStr;  
			       		  }
         	    	}
			     ]
//		  tbar: [
//					  { xtype: 'button',id:'tab-15_add', text: '增加',icon: 'Ext/restful/images/add.png'
//					  },
//					  { xtype: 'button',id:'tab-15_edit', text: '修改',icon: 'Ext/restful/images/cog_edit.png'
//					  },
//					  { xtype: 'button',id:'tab-15_delete', text: '删除',icon: 'Ext/restful/images/delete.png'
//					  }
//				]

})

//办理工作
function addRemar(id){
	    var jobid=id;
	 	Ext.Ajax.request({
				url : 'jobDetail_download',
				success : function() {
						 window.location.href ="download?id="+id+"";
				},
				failure : function() {
					Ext.MessageBox.alert("提示", "无附件可以下载！");
				},
				params : {
						jobId:jobid	
					}
		});		
	
	
	
}
 function banLiJob(id){
	   	  	Ext.Ajax.request({
					url : 'jobDetail_banli',
					success : function() {
						var myform1= new Ext.form.Panel({
				        layout : "form",
				        labelWidth : 200,
				        items: [{
						        layout : "column",
						        border : false,
						        	items: [{
								        	columnWidth :.80,
											layout : "form",
											border : false,
											labelWidth : 30,
								   			items: [{
								   				    xtype : "textarea",
								   				    fieldLabel: '回复内容',
								   				    labelAlign :"right",
										            name: 'huifu',
										            width:200
										        }]		        	
							        	}]
				        	 }]
	 	 })
			var win = new Ext.Window({
					title : "添加回复",
					width : 500,
					height : 200,
					frame:true,
					layout:'fit',
				    items :[myform1],
					buttons : [
							  {text : "确定",
									handler : function() {
										win.getComponent(0).getForm().submit({
													    url : 'jobDetail_huifu',
													    success : function() {
														Ext.Msg.alert('提示', '回复成功');
														win.close();
													},
													failure : function() {
														Ext.Msg.alert('错误', '回复失败');
													},
													waitMsg : "请稍后，正在保存。。。。",
												params : {
															id:id	
															}
											});
									}
								}, {
									text : "重置",
									handler : function() {
										win.getComponent(0).getForm().reset();
									}
								}, {
									text : "取消",
									handler : function() {
														win.close();
													
									}
						}]
	 	}).show();
						
						
					
					 myJobView=Ext.create('AM.view.MyJobView');
					 myJobView.getStore().reload();							 
				},
				failure : function() {
					Ext.MessageBox.alert("提示", "项目正在办理中！");
				},
				params : {
						id:id	
					}
		});		
   
 }
 //添加备注
 function addRemark(id){
		var myform1= new Ext.form.Panel({
			        frame:true,
			        width : 700, 
			        autoHeight : true,
			        layout : "form",
			        labelWidth : 200,
			        items: [{
					        layout : "column",
					        border : false,
					        	items: [{
							        	columnWidth :.80,
										layout : "form",
										border : false,
										labelWidth : 30,
							   			items: [{
							   				    xtype : "textarea",
							   				    fieldLabel: '备注',
							   				    labelAlign :"right",
									            name: 'remark',
									            width:200
									        }]		        	
						        	}]
			        	 }]
 	 })
		var win = new Ext.Window({
				title : "添加备注",
				width : 700,
				height : 200,
				frame:true,
			    items :[myform1],
				buttons : [
						  {text : "确定",
								handler : function() {
									win.getComponent(0).getForm().submit({
												    url : 'jobDetail_addRemark',
												    success : function() {
													Ext.Msg.alert('提示', '添加成功');
													win.close();
												},
												failure : function() {
													Ext.Msg.alert('错误', '添加失败');
												},
												waitMsg : "请稍后，正在保存。。。。",
											  params : {
															id:id	
														}
										});
								}
							}, {
								text : "重置",
								handler : function() {
									win.getComponent(0).getForm().reset();
								}
							}, {
								text : "取消",
								handler : function() {
													win.close();
												
								}
					}]
 	}).show();
		
   
 }
   //完成工作
  function wanchengJob(id){
   	  	Ext.Ajax.request({
				url : 'jobDetail_wancheng',
				success : function() {
					 myJobView=Ext.create('AM.view.MyJobView');
					 myJobView.getStore().reload();						 
				},
				failure : function() {
					Ext.MessageBox.alert("提示", "项目还未办理！");
				},
				params : {
						id:id	
					}
		});	 
 	
 }
